﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Grizzy_X
{
    public partial class NewField : Form
    {
        public bool needAdd = false;
        public string field_Name;
        public string field_Type;
        public string field_Length;
        public string field_Des;

        public NewField()
        {
            InitializeComponent();
            if (FieldTypecomboBox.Text == "字符串(String)")
            {
                textBox2.Enabled = true;
            }
        }

        private void nullcheckBox_CheckedChanged(object sender, EventArgs e)
        {

        }

        //增加字段
        private bool hasInputError = false;
        private void OKbutton_Click(object sender, EventArgs e)
        {
            this.needAdd = true;
            this.field_Name = FieldNametextBox.Text;
            this.field_Type = FieldTypecomboBox.Text;
            if (string.IsNullOrEmpty(FieldNametextBox.Text))
            {
                MessageBox.Show("提示：请输入字段名称！");
                hasInputError = true;
            }
            else
                hasInputError = false;
            if (string.IsNullOrEmpty(textBox2.Text) == true)
            {
                if (textBox2.Enabled == true)
                {
                    MessageBox.Show("提示：请输入字段长度！");
                    hasInputError = true;
                }
                
            }
            else
                hasInputError = false;
            if(hasInputError == false)
            {
                this.field_Length = textBox2.Text;
                this.field_Des = "缺省值：" + textBox1.Text;
                if (nullcheckBox.Checked == true)
                {
                    this.field_Des += "; 允许为空";
                }
                else
                {
                    this.field_Des += "; 不允许为空";
                }

                this.Close();
            }         
        }

        private void cancelbutton_Click(object sender, EventArgs e)
        {
            this.needAdd = false;
            this.Close();
        }

        private void FieldTypecomboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (FieldTypecomboBox.Text != "字符串(String)")
            {
                textBox2.Enabled = false;
            }
        }
    }
}
